<include file="Public/head" />
<link type="text/css" rel="stylesheet" href="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.css" />
<script src="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.js" type="text/javascript"></script>
<style type="text/css">
    .employee .employee_left,.employee_right{width: 50%;float:left;}
    .select2-container .select2-choice > .select2-chosen{text-align: center;}
</style>
</head>
<body>
<include file="Public/common_header" />

<div class="mian">
    <include file="Public/sidebar" menu='xtgl.gysgl' />
    <div class="mianR">
        <h3 class='cha'>片区管理-添加片区</h3>
        <div class="broker clearfix">
            <h4>片区信息</h4>
            <ul class="area-information clearfix">
                <li><span><i>*</i>片区名称：</span><input type="text" value="" name="region_name" id="region_name" /></li>               
                <li><span>片区负责人：</span>
                    <select class="area-select" id="branch_id">
                        <option>请选择分公司</option>
                        <?php foreach ($bc_list as $key => $value): ?>
                            <option value="{$key}">{$value}</option>
                        <?php endforeach ?>
                    </select>
                    <select class="area-select" id="leader">
                        <option value="0">请选择负责人</option>
                        
                    </select>
                </li>
                <li><span><i>*</i>所属城市：</span>
                    <select class="area-select" id="branch_id1">
                        <option>请选择分公司</option>
                        <?php foreach ($bc_list as $key => $value): ?>
                            <option value="{$key}">{$value}</option>
                        <?php endforeach ?>
                    </select>
                    <select class="area-select" id="city">
                        <option value="0">请选择城市</option>
                        
                    </select>
                </li>
            </ul>
            <ul class="area-information clearfix">
                <li><span>摘要：</span><textarea class="abstract-text" placeholder="" id="remark"></textarea></li>               
                <li><span>负责人电话：</span><span class="broker-text" id="mobile"></span></li>        
            </ul>
        </div>
        
       
        <div class="yongBtn clearfix">
            <input type="submit" value="提交" class="queding">
            <input class="quxiao" type="submit" value="返回" onclick="location.href ='/SupplierManage/index/status/4'">
        </div>
    </div>
</div>
    
<script>
    $("#branch_id").change(function () {
        var branch_id = $(this).val();
        $.post("/SupplierManage/getBranchInfo", {"branch_id": branch_id}, function (data) {
            var optstr = '';
            var optstr1 = '';
            if (data.code == 200) {
                if (data.data.shop_developer.length > 0) {
                    $.each(data.data.shop_developer, function (k1, v1) {
                        if (v1.region_name) {
                            optstr += "<option data_phone = '"+ v1.mobile +"' value='" + v1.emp_id + "'>" + v1.real_name +"("+ v1.region_name +")" + "</option>"
                        }else{
                            optstr += "<option data_phone = '"+ v1.mobile +"' value='" + v1.emp_id + "'>" + v1.real_name + "</option>"
                        }
                    });
                };
                // if (data.data.cityInfo.length > 0) {
                //     $.each(data.data.cityInfo, function (k2, v2) {
                //         optstr1 += "<option value='" + v2.city_code + "'>" + v2.city_name + "</option>"
                //     });
                // };
            }
            optstr = "<option value='0' selected='selected'>请选择负责人</option>" + optstr;
            // optstr1 = "<option value='0' selected='selected'>请选择城市</option>" + optstr1;
            $("#leader").html(optstr);
            // $("#city").html(optstr1);
        }, "json");
    });

    $("#branch_id1").change(function () {
        var branch_id = $(this).val();
        $.post("/SupplierManage/getCityByBranchId", {"branch_id": branch_id}, function (data) {
            var optstr2 = '';
            if (data.code == 200) {
                if (data.data.length > 0) {
                    $.each(data.data, function (k2, v2) {
                        optstr2 += "<option value='" + v2.city_code + "'>" + v2.city_name + "</option>"
                    });
                };
            }
            optstr2 = "<option value='0' selected='selected'>请选择城市</option>" + optstr2;
            $("#city").html(optstr2);
        }, "json");
    });

    
    $("#leader").change(function(){
        var mobile = $(this).find("option:selected").attr('data_phone');
        $("#mobile").html(mobile);
    })

    $(".queding").click(function(){
        var region_name = $("#region_name").val();
        if (region_name =='') {
            shibai_alert1('请填写片区名称');
            return;
        };
     
        var city = $("#city").find("option:selected").val();
        if (city < 1) {
            shibai_alert1('请选择所在城市');
            return;
        };
        var leader = $("#leader").find("option:selected").val();
        // if (leader < 1) {
        //     shibai_alert1('请选择负责人');
        //     return;
        // };
        var remark = $("#remark").val();

         var param = {
            'region_name':region_name,
            'city':city,
            'leader':leader,
            'remark':remark,
        };
        $(".queding").attr("disabled","disabled");
        $.post("/SupplierManage/addRegionPost",param,function(data){
            if(data.code!=200){
                shibai_alert(data.msg,2000)
                $(".queding").removeAttr("disabled").removeAttr("style");
            }else{
                btn_alert("添加成功",1500,function(){
                location.href = '/SupplierManage/index/status/4';
            })
            }
        },"json");
    });

</script>
<include file="Public/foot" />